package cn.wolfcode.service.impl;

import cn.wolfcode.domain.Brand;
import cn.wolfcode.mapper.BrandMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.qo.pageResult;
import cn.wolfcode.service.IBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName BrandServiceImpl
 * @Description TODO
 * @Author wdx
 * @Date 2023/4/1 9:58
 */
@Service
public class BrandServiceImpl implements IBrandService {
    @Autowired
    private BrandMapper brandMapper;
    @Transactional
    @Override
    public void deleteByPrimaryKey(Long id) {
        brandMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void insert(Brand brand) {
        brandMapper.insert(brand);
    }

    @Override
    public Brand selectByPrimaryKey(Long id) {
        return brandMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Brand> selectAll() {
        return brandMapper.selectAll();
    }

    @Override
    public void updateByPrimaryKey(Brand brand) {
        brandMapper.updateByPrimaryKey(brand);
    }

    @Override
    public pageResult<Brand> queryBrand(QueryObject qo) {
        int count = brandMapper.selectForCount(qo);
        if(count <= 0){
            return new pageResult<>(qo.getCurrentPage(),qo.getPageSize(),count,new ArrayList());
        }
        List<Brand> brands = brandMapper.queryBrand(qo);
        return new pageResult<>(qo.getCurrentPage(),qo.getPageSize(),count,brands);
    }
}
